package com.algorithm.binary;/*
 *@Author:DOWN
 *@Date:2022/1/21 10:15
 *@Comment:二分递归查找法 适用于 有序
 */

public class BinaryRecursionSeach {
    public static <E extends Comparable<E>> int seach(E[] args, E target) {
        return seach(args, 0, args.length - 1, target);
    }

    public static <E extends Comparable<E>> int seach(E[] args, int l, int r, E target) {
        if (l > r) {
            return -1;
        }
        int middle = l + (r - l) / 2;
        if (args[middle].compareTo(target) == 0) {
            return middle;
        } else if (args[middle].compareTo(target) > 0) {
            return seach(args, l, middle - 1, target);
        } else {
            return seach(args, middle + 1, r, target);
        }
    }
}
